/**
 * Created by yqj on 2017/2/20.
 */
const dictionaryController = require('../controller/dictionary-controller.js');
const dictionaryApi = {

    getDictionary (req, res) {
        let type = req.params.type;
        let method;
        switch (type) {
            case 'booktype':
                method = 'getBookType';
                break;
            case 'brand':
                method = 'getBrand';
                break;
            case 'grade':
                method = 'getGrade';
                break;
            case 'province':
                method = 'getProvinces';
                break;
            case 'selfcontenttype':
                method = 'getSelfBuildContentType';
                break;
            case 'series':
                method = 'getSeries';
                break;
            case 'subject':
                method = 'getSubjects';
                break;
            case 'topictype':
                method = 'getTopicType';
                break;
            case 'version':
                method = 'getVersion';
                break;
            case 'volume':
                method = 'getVolume';
                break;
            default:
                res.status(400).json({message: 'path is incomplete.'});
                return;
                break;
        }
        return dictionaryController[method]()
            .then((data) => {
                res.json({message: data.message, result: data.result});
            }, (err) => {
                res.status(err.status).json({message: err.message});
            })
    }
};

module.exports = dictionaryApi;
